package br.com.eSink.util;

import java.io.File;

import android.os.Environment;
import android.util.Log;

public class Storage {
	
	/* Checks if external storage is available for read and write */
    public static boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }
   
    /* Checks if external storage is available to at least read */
    public static boolean isExternalStorageReadable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state) ||
            Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            return true;
        }
        return false;
    }
    
    public static File getMusicStorageDir(String musicName) {
        // Get the directory for the user's public pictures directory.
    	if(isExternalStorageReadable() && isExternalStorageWritable()){
		    File file = new File(Environment.getExternalStoragePublicDirectory(
		            Environment.DIRECTORY_MUSIC), musicName);
		    if (!file.mkdirs()) {
		        Log.e("Erro", "Directory not created");
		    }	
		    return file;
    	}
    	return null;
    }


}
